package top.topsmart.api.bycenter.controller;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.oas.annotations.EnableOpenApi;
import top.topsmart.api.bycenter.service.DynamicService;
import top.topsmart.api.bycenter.util.Result;

import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.Date;

@Api(tags = "动态业务")
@RestController
@RequestMapping(value = "dynamic", method = {RequestMethod.GET, RequestMethod.POST})

public class DynamicController {
    @Autowired
    private DynamicService dynamicService;

    @PostMapping("release")
    @ApiOperation("release")
    public Result release(@RequestBody JSONObject dynamic) {
        System.out.println(new SimpleDateFormat("yyy-MM-dd hh:mm:ss").format(new Date()) + "  正在处理dynami/release");
        Result result = dynamicService.release(dynamic);
        System.out.println(result);
        return result;
    }

    @PostMapping("update")
    @ApiOperation("update")
    public Result update(@RequestBody JSONObject dynamic) {
        System.out.println(new SimpleDateFormat("yyy-MM-dd hh:mm:ss").format(new Date()) + "  正在处理dynami/update");
        return dynamicService.update(dynamic);
    }

    @PostMapping("backByType")
    @ApiOperation("backByType")
    public Result backByType(@RequestBody JSONObject param) {
        System.out.println(new SimpleDateFormat("yyy-MM-dd hh:mm:ss").format(new Date()) + "  正在处理dynamic/backByType");
        Result result = dynamicService.backByType(param);
        System.out.println(JSONObject.toJSONString(result));
        return result;
    }
}
